<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="../application/vue.js"></script>
</head>
<body>
    <div class="app">
        <p>user:{{user}}</p>
        <input type="text" v-model="user.name">
        <input type="button" value="添加age属性" @click="addAge()">
        <hr>
        <p>user1:{{user1}}</p>
        <input type="text" v-model="user1.name">
        <input type="text" v-model="user1.age">
        <p>user1.skill:{{user1.skill}}</p>
        <p v-text="user1.skill"></p>
        <input type="button" value="添加skill属性" @click="addSkill()">
        <hr>
        <p>arr:{{arr}}</p>
        <input type="button" value="改变下标值" @click="arr[1]='ccc'">
        <input type="button" value="添加新属性" @click="arr[arr.length]='ddd'">
        <!-- 上述方法都不行，得用变异方法进行数组的属性添加 -->
        <input type="button" value="添加属性" @click="arr.push('eee')">
        <hr>
        <p>user.id:{{user.id}}</p>
        <input type="text" v-model="user.id">
        <input type="button" value="删除数据劫持" @click="deleteIt()">
    </div>
</body>
<script>
    var vm =new Vue({
        el:".app",
        data:{
            user:{
                name:"王梦云",
                id:1001
            },
            user1:{},
            arr:[1,2,3]
        },
        methods:{
            addAge(){
                // this.user.age=23;
                // console.log(this);
                // this.$set(this.user,"age",23);
                // this.$set(this.$data,"info","xixi");//不可以,报错
                Vue.set(this.user,"age",23);
            },
            addSkill(){
                this.user1.skill="html";
            },
            deleteIt(){
                this.$delete(this.user,"id");
            }
        }
    })
</script>
</html>